
const api = require("../../utils/api")
const getwxphone = require("../../utils/getwxphone")
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    index2: 0,
    index3: 0,
    index4: 0,
    nianfen: ['请选择年份'],
    leibie: ['请选择类别'],
    dishi: ['请选择地市'],
    xueli: ['请选择学历'],
    theList: '',
  },
  ggyy() {
    wx.navigateToMiniProgram({
      appId: 'wx6b75078563b749b0', //appid
      path: '/pages/test/test?shortid=1231631&owner=61132', 
      envVersion: 'release', //开发版develop 开发版 trial   体验版 release 正式版 
      success(res) {
        console.log('成功')
      }
    })
  },
  bindPickerChange: function (e) {
    let num = e.detail.value;
    let _ = this;
    console.log('nianfen发送选择改变，携带值为', _.data.nianfen[num]);
    this.setData({
      index: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=46777&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'nianfen',
        grtext: _.data.nianfen[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        list.push('请选择类别')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].leibie)
        }
        _.setData({
          leibie: list
        });
      }
    })
  },
  bindPickerChange2: function (e) {
    let num2 = e.detail.value;
    let _ = this;
    console.log('leibie发送选择改变，携带值为', _.data.leibie[num2]);
    this.setData({
      index2: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=46777&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'leibie',
        grtext: _.data.leibie[num2],
        onefiled: 'nianfen',
        onetext: _.data.nianfen[this.data.index]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        list.push('请选择地市')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dishi)

        }
        _.setData({
          dishi: list
        });
      }
    })
  },
  bindPickerChange3: function (e) {
    let num3 = e.detail.value;
    let _ = this;
    console.log('dishi发送选择改变，携带值为', _.data.dishi[num3]);
    this.setData({
      index3: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=46777&callback=?', //接收url
      data: {
        level: '4',
        grfiled: 'dishi',
        grtext: _.data.dishi[num3],
        onefiled: 'nianfen',
        onetext: _.data.nianfen[this.data.index],
        twofiled: 'leibie',
        twotext: _.data.leibie[this.data.index2],
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        list.push('请选择学历')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xueli)
        }
        _.setData({
          xueli: list
        });
      }
    })
  },
  bindPickerChange4: function (e) {
    let num4 = e.detail.value;
    let _ = this;
    console.log('xueli发送选择改变，携带值为', _.data.xueli[num4]);
    this.setData({
      index4: e.detail.value
    })
  },

  onLoad: function (options) {
    
    api.load(options)
    var _ = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=46777&callback=?', //接收url
      data: {
        level: '1',
        nianfen: '',
        sstimes:Date.parse(new Date())
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择年份')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].nianfen)
        }
        _.setData({
          nianfen: list
        });
      }
    })


    var phone = wx.getStorageSync('zwjsphone')
    if (phone) {
      _.setData({
        phone: phone
      })
    }
    console.log(options)
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
  },

  getPhoneNumber(e) {
    var _ = this;
    var flag = _.data.flag;
    if (flag) {
      const info = {
        area: wx.getStorageSync('area'),
        agent: wx.getStorageSync('agent'),
        page: wx.getStorageSync('page'),
        activeId: 21
      }

      getwxphone(e.detail.code, 46777, 'chaxun', info)
        .then(res => {
          console.log(res);
          wx.setStorageSync('zwjsphone', res.result)
          var nianfen = _.data.nianfen[_.data.index];
          var leibie = _.data.leibie[_.data.index2];
          var dishi = _.data.dishi[_.data.index3];
          var xueli = _.data.xueli[_.data.index4];
          wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=46777&callback=?",
            data: {
              nianfen: nianfen,
              leibie: leibie,
              xueli: xueli,
              dishi: dishi,
              limits: '100'
            }, //接收参数
            success(res) { //返回
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              };
              console.log(theJson)
              _.setData({
                theList: theJson.lists
              })
              console.log(_.data.theList)
              wx.pageScrollTo({
                scrollTop: 500,
                duration: 300
              })
            }
          })
        })
        .catch(err => {
          console.log(err);
        })
    } else {
        wx.showToast({
          title: '请先勾选隐私协议！',            
          icon: 'none'
        })
      }
  },  



  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },

  tijiao: function (res) {
    var _ = this;
    var nianfen = _.data.nianfen[_.data.index];
    var leibie = _.data.leibie[_.data.index2];
    var dishi = _.data.dishi[_.data.index3];
    var xueli = _.data.xueli[_.data.index4];
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=46777&callback=?",
      data: {
        nianfen: nianfen,
        leibie: leibie,
        xueli: xueli,
        dishi: dishi,
        limits: '100'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        _.setData({
          theList: theJson.lists
        })
        console.log(_.data.theList)
        wx.pageScrollTo({
          scrollTop: 500,
          duration: 300
        })
      }
    })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})